package com.android.settings.ios;

import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
//import android.os.SystemProperties;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.Preference;

public class OsUtils {

    public static final String ACTION_SELECT_MENU_CHANGED = "os.action.SELECT_MENU_CHANGED";

    private static LocalBroadcastManager sLocalBroadcastManager;

    public static int sTotalAppCount = 0;

    public static void init(Application app) {
        sLocalBroadcastManager = LocalBroadcastManager.getInstance(app);
    }

    public static void notifyMenuSelected(Preference preference) {
        if (preference == null) {
            return;
        }

        Intent intent = new Intent(ACTION_SELECT_MENU_CHANGED);
        String key = preference.getKey();
        if (key != null) {
            intent.putExtra("key", key);
        } else {
            CharSequence title = preference.getTitle();
            if (title != null) {
                intent.putExtra("title", title);
            }
        }
        sLocalBroadcastManager.sendBroadcast(intent);
    }

    /**
     * 注册菜单选中时高亮背景效果
     *
     * @param receiver
     */
    public static void registerSelectEffect(BroadcastReceiver receiver) {
        IntentFilter filter = new IntentFilter();
        filter.addAction(ACTION_SELECT_MENU_CHANGED);
        sLocalBroadcastManager.registerReceiver(receiver, filter);
    }

    /**
     * 取消注册
     *
     * @param receiver
     */
    public static void unregisterSelectEffect(BroadcastReceiver receiver) {
        sLocalBroadcastManager.unregisterReceiver(receiver);
    }

    public static String getPropString(String key, String def) {
        //return SystemProperties.get(key, def);
        return def;
    }
}
